<?php

define('IN_API', true);
require_once '../../framework/bootstrap.inc.php';
require_once 'defines.php';

$id = $_GPC['id'];
$settings = pdo_get("uni_account_modules", array("module" => MODULE_NAME , "uniacid" => $id));
$settings = unserialize($settings['settings']);
$content = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_sc_publisher_get.ashx?relation_app=common&info_type=1&page_no=1&page_size=50&appkey='.$settings['appkey'].'&sid='.$settings['sid']),true);
$map = $content['tbk_sc_publisher_info_get_response']['data']['inviter_list']['map_data'];
foreach($map as $k => $v){
	if($v['rtag']){
		$v['rtag'] = explode("A",$v['rtag'])[0];
		if($settings['system_type'] == 1){
			$user = pdo_get(MODULE_NAME."_user_u", array("uid" => $v['rtag'], "system_id" => $settings['system_id']));
			if($user){
				pdo_update(MODULE_NAME."_user_u", array("relation_id" => $v['relation_id']), array("user_id" => $user['user_id'] , "system_id" => $settings['system_id']));
			}
		}else{
			$user = pdo_get(MODULE_NAME."_user", array("uid" => $v['rtag'], "uniacid" => $id));
			if($user){
				pdo_update(MODULE_NAME."_user", array("relation_id" => $v['relation_id']), array("user_id" => $user['user_id'], "uniacid" => $id));
			}
		}
		
		
	}
}
